package my.jwds.p876;

import my.jwds.p21.ListNode;

public class MiddleNode {

    public static void main(String[] args) {
        MiddleNode obj = new MiddleNode();
        System.out.println(obj.middleNode(ListNode.to(new int[]{1,2,3,4,5})));
    }
    public ListNode middleNode(ListNode head) {
        ListNode fast = head;
        ListNode slow = head;
        while(fast != null && fast.next != null){
            slow = slow.next;
            fast = fast.next.next;
        }
        return slow;
    }
}
